package com.dubbo.nacos;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.dubbo.nacos.service.DubboNacousDemoService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.PropertySource;

import javax.annotation.PostConstruct;
import java.io.IOException;

@EnableDubbo
@PropertySource(value = "classpath:/config/consumer.properties")
public class ConsumerDemoApplication {

    @Reference(version = "${demo.service.version}")
    private DubboNacousDemoService dubboNacousDemoService;

    @PostConstruct
    public void start() {
        for (int i = 0; i < 10; i++) {
            System.out.println(dubboNacousDemoService.sayHello("欢迎光临，钢铁的意志！"));
        }
    }

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        // 注册 @Configuration Class
        context.register(ConsumerDemoApplication.class);
        // 启动当前上下文
        context.refresh();

        System.out.println("服务消费者已启动...");
        System.in.read();
    }

}
